var express = require('express');
var router = express.Router();
var multiparty = require("multiparty");
var path=require('path');

//图片上传到本地
router.post("/upload", function (req, res) {
  var form = new multiparty.Form({ uploadDir: "./public/images" });
  form.parse(req, function (err, fields, files) {
    console.log('index',req.body);
    if (err) {
      res.send(err);
    } else {
      var p = files.file[0].path.substring(
        files.file[0].path.indexOf("images")
      );
      res.send({filename:path.basename(p)});
    }
  });
});

module.exports = router;


